<?php
    /**
     * Created by PhpStorm.
     * User: timeteam
     * Date: 18-11-15
     * Time: 上午10:56
     */

    namespace app\store\logic;


    use app\store\model\LogisticsModel;
    use app\store\model\OrderModel;
    use think\Db;
    use think\Exception;

    class DeliverGoodsLogic
    {

        /**
         * 发货操作
         * @param $order_sn
         * @param $code
         * @param $company
         * @return bool
         */
        static public function Send($order_sn, $code, $company)
        {
            try {
                Db::startTrans();
                $OrderInfoModel = OrderModel::where(['order_sn' => $order_sn])->find();
                $OrderInfoModel->status = OrderModel::STATUS_DELIVER;
                $OrderInfoModel->save();
                LogisticsModel::create([
                    'order_sn' => $order_sn,
                    'code' => $code,
                    'company' => $company,
                    'type' => LogisticsModel::TYPE_DELIVER,
                ]);
                Db::commit();
                return true;
            } catch (Exception $exception) {
                Db::rollback();
                return false;
            }
        }

    }